#ifndef IMGRAPHICS_H
#define IMGRAPHICS_H

#define WIN32_LEAN_AND_MEAN

#include "imGraphicsInterfaces.h"
#include <Windows.h>

namespace imGraphics {
	// Renderer global
	// The renderer exposes functions such as loading textures and new mesh
	// drivers, and so needs to be accessible from many places. The reason
	// is I found making the 'renderer' the central pillar of the graphics
	// component to be convenient.
	extern iRenderer* g_GFX;

	extern iTexture* g_DefTextures[NUMTEXTURES];

	// Library component
	// Used to mount and load a graphics library of the user's choice
	class RendererLib {
	private:
		iRenderer *pRenderer;
		HINSTANCE hInst;
		HMODULE hDLL;
	public:
		RendererLib(void) {memset(this, NULL, sizeof(this));};
		RendererLib(HINSTANCE);
		~RendererLib(void);

		void InitWindow(void);
		HRESULT MountLib(char *chAPI);

		void Release(void);
		iRenderer* GetRenderer(void) { return pRenderer; };
		HMODULE GetModule(void) { return hDLL; };
	};

	// Textures
	iTexture* GetTexture(std::string &Path);
	void InitDefaultTextures();

	//
	// Window class
	//
	LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

	class imWindow {
	private:
		unsigned int m_iWidth, m_iHeight;
		DisplayMode m_dDisplayMode;
		HWND m_WndHandle;
		HINSTANCE m_Instance;
		std::string m_strTitle;
	public:
		imWindow();
		imWindow(HINSTANCE Instance);

		void ConfigFromFile(Config* Cfg);

		void Close();

		void Init();
		void Init(HINSTANCE Instance);
		void SetSize(unsigned int iWidth, unsigned int iHeight);
		void SetMode(DisplayMode dDisplay);
		void SetTitle(std::string strTitle);

		HWND GetHandle();
	};
}

extern "C" {
	//
	// Standard C declaration
	//

	//HRESULT __declspec(dllexport) CreateRenderDevice(HINSTANCE hDLL, iRenderer **pInterface);
	//HRESULT __declspec(dllexport) ReleaseRenderDevice(iRenderer **pInterface);

	//
	// VC++ friendly declaration
	//

	typedef HRESULT (*CREATERENDERDEVICE)
						(HINSTANCE hDLL, imGraphics::iRenderer **pInterface);

	typedef HRESULT (*RELEASERENDERDEVICE)
						(imGraphics::iRenderer **pInterface);
};

#endif